package com.jianjunhuang.demo.wechatdemo;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener, TextWatcher {

    private ImageView finishImg;
    private EditText phoneEdt;
    private Button nextBtn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_activity);

        finishImg = findViewById(R.id.login_return_img);
        phoneEdt = findViewById(R.id.login_phone_edt);
        nextBtn = findViewById(R.id.login_next_btn);

        finishImg.setOnClickListener(this);
        phoneEdt.addTextChangedListener(this);
        nextBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.login_return_img: {
                finish();
                break;
            }
            case R.id.login_next_btn: {
                Intent intent = new Intent(this, HomepageActivity.class);
                startActivity(intent);
                break;
            }
        }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (s.length() == 0) {
            setNextBtnColor(Color.parseColor("#a3dea3"),
                    Color.parseColor("#f1f1f1"));
        } else {
            setNextBtnColor(Color.parseColor("#1aad19"),
                    Color.parseColor("#ffffff"));
        }
    }

    @Override
    public void afterTextChanged(Editable s) {

    }

    private void setNextBtnColor(int backgroundColor, int textColor) {
        nextBtn.setBackgroundColor(backgroundColor);
        nextBtn.setTextColor(textColor);
    }
}
